<?php

namespace App\Http\Middleware;

use App\Hit;
use App\Writing;
use Closure;
use Illuminate\Support\Carbon;

class Hits
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
//       $hit= Hit::where('created_at','<',Carbon::tomorrow())
//           ->where('mac_id',$_SERVER['HTTP_USER_AGENT'])
//           ->where('writing_id',$request->id)
//           ->first();
//       if(!$hit){
//
//           $hit=new Hit();
//           $hit->mac_id=$_SERVER['HTTP_USER_AGENT'];
//           $hit->ip=$request->ip();
//           $hit->writing_id=$request->id;
//           $hit->save();
//           $Writing=Writing::find($request->id);
//           $Writing->increment('hits',1);
//       }

        return $next($request);
    }
}
